﻿using Pantry.DataAccess;
using Pantry.Entity;

namespace Pantry.Business
{
    public class TeamBus : PantryBus
    {
        private TypeOfBusinessBus typeOfBusinessBus;

        public TeamBus() 
        {
            PantryDao = new TeamDao();
        }
         
        public TypeOfBusinessSearch RetrieveTypeOfBusinessByDepartment(int typeOfBusinessId)
        {
            if (typeOfBusinessId < 1)
            {
                return null;
            }

            if (typeOfBusinessBus==null)
            {
                typeOfBusinessBus = new TypeOfBusinessBus();
            }

            var typeOfBusinessSearchTable = typeOfBusinessBus.TypeOfBusinessById(typeOfBusinessId);
            if (typeOfBusinessSearchTable.Rows.Count<1)
            {
                return null;
            }

            var typeOfBusinessSearch = new TypeOfBusinessSearch
            {
               Id = (int) typeOfBusinessSearchTable.Rows[0]["Id"],
               SicCode = typeOfBusinessSearchTable.Rows[0]["SicCode"].ToString(),
               TypeName = typeOfBusinessSearchTable.Rows[0]["TypeName"].ToString()
            };

            return typeOfBusinessSearch;
        }

    }
}
